package com.vehicle.service.imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.vehicle.bean.DataGridView;
import com.vehicle.bean.PageVo;
import com.vehicle.mapper.ApplyUseMapper;
import com.vehicle.mapper.DriverMapper;
import com.vehicle.pojo.ApplyUse;
import com.vehicle.pojo.Check;
import com.vehicle.pojo.Driver;
import com.vehicle.service.ApplyUseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class ApplyUseServiceImpl implements ApplyUseService {

    @Autowired
    private ApplyUseMapper applyUseMapper;

    @Autowired
    private DriverMapper driverMapper;

    @Override
    public DataGridView findAllApplyUse(PageVo pageVo,String status) {
        PageHelper.startPage(pageVo.getPage(),pageVo.getLimit());
        List<ApplyUse> applyUses =  applyUseMapper.findAllApplyUse(status);
        DataGridView dataGridView = new DataGridView();
        PageInfo pageInfo = new PageInfo<>(applyUses);
        dataGridView.setCount(pageInfo.getTotal());
        dataGridView.setData(applyUses);
        return dataGridView;
    }

    @Override
    public void deApplyUse(Integer applyid) {
        applyUseMapper.delApplyUse(applyid);
    }

    //添加用车申请
    @Override
    public void applyAdd(ApplyUse applyUse) {
        applyUseMapper.applyAdd(applyUse);
    }

    //查询所有司机信息
    @Override
    public List<Driver> findAllDriver() {
        List<Driver> driverList = driverMapper.selectDrivers();
        return driverList;
    }

    @Override
    public ApplyUse selectApplyUseById(Integer applyid) {
       ApplyUse applyUse =  applyUseMapper.selectApplyUseById(applyid);
       return applyUse;
    }

    @Override
    public void updateApplyUseState(Integer applyid, Integer status) {
        applyUseMapper.updateApplyUseState(applyid,status);
    }

    @Override
    public void updateCarPlateByApplyId(String carplate, Integer applyid, Date sendCarTime,String sendCarUser) {
        applyUseMapper.updateCarPlateByApplyId(carplate,applyid,sendCarTime,sendCarUser);
    }
}
